package org.hot100_6.leetcode101;

import org.leetcode.TreeNode;

public class Solution {
    public boolean isSymmetric(TreeNode root) {

        return isSame(root.left,root.right);
    }

    public boolean isSame(TreeNode left,TreeNode right){

        if (left==null && right==null){
            return true;
        }

        if (left==null && right!=null){
            return false;
        }

        if (left!=null && right==null){
            return false;
        }

        if (right.val!=left.val){
            return false;
        }

        boolean outSide = isSame(left.left, right.right);
        boolean inSide = isSame(left.right, right.left);

        return outSide && inSide;
    }

}
